<?php


namespace app\common\models;


use think\model;

class Error extends Model
{
    //  连接数据库
    protected $connection = 'exam2';
    //  连接表名
    protected $name = 'error';
    //  自动写入时间戳字段
    protected $createTime = 'create_at';
    protected $updateTime = 'update_at';

    // 分页查询,获取列表
    public function fetchListByWhere($where, $order = ['id' => 'desc'], $field = '*', $page = 1, $pageSize = 10)
    {
        return $this->field($field)->where($where)->order($order)->page($page, $pageSize)->select()->toArray();
    }

    //关联前台用户表
    public function apimember()
    {
        return $this->hasOne(ApiMember::class, 'id', 'api_member_id')->field('id,nickname');
    }

    //关联年级表
    public function grade()
    {
        return $this->hasOne(Grade::class, 'id', 'grade_id')->field('id,title');
    }

    //关联课程表
    public function course()
    {
        return $this->hasOne(Course::class, 'id', 'course_id')->field('id,title');
    }

    //关联题库表
    public function question()
    {
        return $this->hasOne(Question::class, 'id', 'question_id')->field('id,title,paper_id');
    }
}